042 Weighted interpolation
Smoothing
We have seen that geospatial datasets often have missing values, and also that the quality (or better, uncertainty) from one pixel to the next, in space or time, may vary.
If we have some expectation that the data should be smooth (in time and/or space), then we can use ideas of regularisation (smoothing) to improve the accuracy of the data. Note that any such claimed improvement is conditional on the data being smooth. Any violation of that will be inconsistent with our assumptions and may lead us to mis-interpret the data. Although we will not be doing so here, we can also provide updates on the data uncertainty after regularisation.
When we regularise the data, we want to respond to the variable uncertainty of the data. We have seen in 041_GDAL_timeseries that we can phrase the inverse of uncertainty (i.e. certainty) via a weight. For a single parameter (i.e. assumed no correlations between parameters), this is just a single weight to associate with a data point. If there is no data at some location, we simply have a weight of zero. So, we want to do a weighted regularisation responding to this.
There are many approaches to weighted interpolation. One such is to use a convolution smoothing operation.
In convolution, we combine a signal $y$ with a filter $f$ to achieve a filtered signal. For example, if we have an noisy signal, we will attempt to reduce the influence of high frequency information in the signal (a 'low pass' filter, as we let the low frequency information pass).
In this approach, we define a digital filter (convolution filter) that should be some sort of weighted average function. A typical filter is the Gaussian, defined by the parameter $\sigma$. The larger the value of $\sigma$, the 'wider' the filter, which means that the weighted average will be takjen over a greater extent.
We do not expect you to be overly concerned with the code in these sections below, as the main effort should be directed at understanding smoothing and interpolation at this point.
Gaussian Filter
Let's look at this filter:
from IPython.display import HTML
from geog0111.demofilt1 import demofilt1
show1 = HTML(demofilt1().to_jshtml())

show1
Convolution
A digital (discrete) convolution uses a sampled signal and filter (represented on a grid).
Without going into the maths, the convolution operates by running the filter centred on $x_c$ over the extent of the signal as illustrated below.
At each value of $x_c$, the filter is multiplied by the signal. Clearly, where the filter is zero, the influence of the signal is zero. So, the filter effectively selects a local window of data points (shown as green crosses below). The result, i.e. the filtered signal, is simply the weighted average of these local samples. This can be seen in the lower panel, where the green dot shows the filtered signal at $x_c$.
from IPython.display import HTML
from geog0111.demofilt3 import demofilt3
show2=HTML(demofilt3().to_jshtml())

show2
Filter width and degree of smoothing
The convolution of a low pass ('smoothing') filter with a signal results in a smoothing of the signal:
from IPython.display import HTML
from geog0111.demofilt2 import demofilt2
show3 = HTML(demofilt2().to_jshtml())

show3